/**
 * Copyright (C) 2018-2019
 * All rights reserved, Designed By www.joolun.com
 */
package com.aimaterials.web.api;

import com.aimaterials.common.core.controller.BaseController;
import com.aimaterials.common.core.domain.AjaxResult;
import com.aimaterials.common.core.domain.entity.SysUser;
import com.aimaterials.common.core.domain.model.LoginUser;
import com.aimaterials.common.core.page.TableDataInfo;
import com.aimaterials.common.utils.ServletUtils;
import com.aimaterials.framework.web.service.TokenService;
import com.aimaterials.resource.domain.ResResource;
import com.aimaterials.resource.domain.ResStereoscopic;
import com.aimaterials.resource.service.IResResourceService;
import com.aimaterials.resource.service.IResStereoscopicService;
import com.aimaterials.weixin.entity.LoginMaDTO;
import com.aimaterials.weixin.entity.WxOpenDataDTO;
import com.aimaterials.weixin.entity.WxUser;
import com.aimaterials.weixin.service.WxUserService;
import com.aimaterials.weixin.utils.ThirdSessionHolder;
import com.aimaterials.weixin.utils.WxMaUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 微信教材列表
 */
@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("/weixin/api/ma/jiaocai")
@Api(value = "wxuser", tags = "移动端教材API")
public class WxJiaocaiApi extends BaseController {

	@Autowired
	private IResStereoscopicService resStereoscopicService;

	@Autowired
	private TokenService tokenService;

	@Autowired
	private IResResourceService resResourceService;

	/**
	 *
	 * @param resStereoscopic
	 * @return
	 */
	@ApiOperation(value = "移动端获得教材列表")
	@GetMapping("/list")
	public TableDataInfo list(ResStereoscopic resStereoscopic)
	{
		startPage();
		List<ResStereoscopic> list = resStereoscopicService.selectResStereoscopicList(resStereoscopic);
		return getDataTable(list);
	}

	/**
	 * 获得教材中的资源列表
	 */
	@GetMapping("/resourceList")
	public TableDataInfo list(ResResource resResource)
	{
		List<ResResource> list = resResourceService.selectResResourceList(resResource);
		return getDataTable(list);
	}

	/**
	 * 获取立体教材详细信息
	 */
	@GetMapping(value = "/{stereoscopicId}")
	public AjaxResult getInfo(@PathVariable("stereoscopicId") Long stereoscopicId)
	{
		return AjaxResult.success(resStereoscopicService.selectResStereoscopicById(stereoscopicId));
	}

	/**
	 * 获取立体教材详细信息
	 */
	@GetMapping(value = "/getResourceByORCode")
	public AjaxResult getResourceByORCode(@RequestParam(value = "qrCode",required = true) String qrCode)
	{
		return AjaxResult.success(resStereoscopicService.selectResByQrCode(qrCode,null));
	}

}
